<!DOCTYPE html>
<html>

<head>
  <title>Quarkus - Infinispan Client</title>
  <script id="adobe_dtm" src="https://www.redhat.com/dtm.js" type="text/javascript"></script>
  <script src="/assets/javascript/highlight.pack.js" type="text/javascript"></script>
  <META HTTP-EQUIV='Content-Security-Policy' CONTENT="default-src 'none'; script-src 'self' 'unsafe-eval' 'sha256-ANpuoVzuSex6VhqpYgsG25OHWVA1I+F6aGU04LoI+5s=' 'sha256-ipy9P/3rZZW06mTLAR0EnXvxSNcnfSDPLDuh3kzbB1w=' js.bizographics.com https://www.redhat.com assets.adobedtm.com jsonip.com https://ajax.googleapis.com https://www.googletagmanager.com https://www.google-analytics.com https://use.fontawesome.com; style-src 'self' https://fonts.googleapis.com https://use.fontawesome.com; img-src 'self' *; media-src 'self' ; frame-src https://www.googletagmanager.com https://www.youtube.com; frame-ancestors 'none'; base-uri 'none'; object-src 'none'; form-action 'none'; font-src 'self' https://use.fontawesome.com https://fonts.gstatic.com;">
  <META HTTP-EQUIV='X-Frame-Options' CONTENT="DENY">
  <META HTTP-EQUIV='X-XSS-Protection' CONTENT="1; mode=block">
  <META HTTP-EQUIV='X-Content-Type-Options' CONTENT="nosniff">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="Quarkus: Supersonic Subatomic Java">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:site" content="@QuarkusIO"> 
  <meta name="twitter:creator" content="@QuarkusIO">
  <meta property="og:url" content="https://quarkus.io/guides/infinispan-client" />
  <meta property="og:title" content="Quarkus - Infinispan Client" />
  <meta property="og:description" content="Quarkus: Supersonic Subatomic Java" />
  <meta property="og:image" content="/assets/images/quarkus_card.png" />
  <link rel="canonical" href="https://quarkus.io/guides/infinispan-client">
  <link rel="shortcut icon" type="image/png" href="/favicon.ico" >
  <link rel="stylesheet" href="https://quarkus.io/guides/stylesheet/config.css" />
  <link rel="stylesheet" href="/assets/css/main.css" />
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
  <link rel="alternate" type="application/rss+xml"  href="https://quarkus.io/feed.xml" title="Quarkus">
  <script src="https://quarkus.io/assets/javascript/goan.js" type="text/javascript"></script>
  <script src="https://quarkus.io/assets/javascript/hl.js" type="text/javascript"></script>
</head>

<body class="guides">
  <!-- Google Tag Manager (noscript) -->
  <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NJWS5L"
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  <!-- End Google Tag Manager (noscript) -->

  <div class="nav-wrapper">
  <div class="grid-wrapper">
    <div class="width-12-12">
      <input type="checkbox" id="checkbox" />
      <nav id="main-nav" class="main-nav">
  <div class="container">
    <div class="logo-wrapper">
      
        <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_600px_reverse.png" class="project-logo" title="Quarkus"></a>
      
    </div>
    <label class="nav-toggle" for="checkbox">
      <i class="fa fa-bars"></i>
    </label>
    <div id="menu" class="menu">
      <span>
        <a href="/get-started/" class="">Get Started</a>
      </span>
      <span>
        <a href="/guides/" class="active">Guides</a>
      </span>
      <span>
        <a href="/community/" class="">Community</a>
      </span>
      <span>
        <a href="/support/" class="">Support</a>
      </span>
      <span>
        <a href="/blog/" class="">Blog</a>
      </span>
      <span>
        <a href="https://code.quarkus.io" class="button-cta secondary white">Start Coding</a>
      </span>
    </div>
  </div>
      </nav>
    </div>
  </div>
</div>

  <div class="content">
    <div class="guide">
  <div class="width-12-12">
    <h1 class="text-caps">Quarkus - Infinispan Client</h1>
    <div class="hide-mobile toc"><ul class="sectlevel1">
<li><a href="#configuration">Configuration</a></li>
<li><a href="#serialization-key-value-types-support">Serialization (Key Value types support)</a>
<ul class="sectlevel2">
<li><a href="#annotation-based-serialization">Annotation based Serialization</a></li>
<li><a href="#user-written-serialization">User written serialization</a></li>
</ul>
</li>
<li><a href="#dependency-injection">Dependency Injection</a></li>
<li><a href="#querying">Querying</a></li>
<li><a href="#counters">Counters</a></li>
<li><a href="#near-caching">Near Caching</a></li>
<li><a href="#encryption">Encryption</a></li>
<li><a href="#authentication">Authentication</a></li>
<li><a href="#additional-features">Additional Features</a></li>
</ul></div>
    <div>
      <div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>Infinispan is an in memory data grid that allows running in a server outside of application processes. This extension
provides functionality to allow the client that can connect to said server when running in Quarkus.</p>
</div>
<div class="paragraph">
<p>More information can be found about Infinispan at <a href="https://infinispan.org" class="bare">https://infinispan.org</a> and the client/server at
<a href="https://infinispan.org/docs/dev/user_guide/user_guide.html#client_server" class="bare">https://infinispan.org/docs/dev/user_guide/user_guide.html#client_server</a></p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="configuration"><a class="anchor" href="#configuration"></a>Configuration</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Once you have your Quarkus project configured you can add the <code>infinispan-client</code> extension
to your project by running the following from the command line in your project base directory.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">./mvnw quarkus:add-extension -Dextensions="infinispan-client"</code></pre>
</div>
</div>
<div class="paragraph">
<p>This will add the following to your pom.xml</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs">&lt;dependency&gt;
    &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
    &lt;artifactId&gt;quarkus-infinispan-client&lt;/artifactId&gt;
&lt;/dependency&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The Infinispan client is configurable in the <code>application.properties</code> file that can be
provided in the <code>src/main/resources</code> directory. These are the properties that
can be configured in this file:</p>
</div>
<div class="paragraph configuration-legend">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> Configuration property fixed at build time - All other configuration properties are overridable at runtime</p>
</div>
<table class="tableblock frame-all grid-all stretch configuration-reference searchable">
<colgroup>
<col style="width: 80%;">
<col style="width: 10%;">
<col style="width: 10%;">
</colgroup>
<tbody>
<tr>
<th class="tableblock halign-left valign-top"><p class="tableblock"><a id="quarkus-infinispan-client_configuration"></a><a href="#quarkus-infinispan-client_configuration">Configuration property</a></p></th>
<th class="tableblock halign-left valign-middle"><p class="tableblock">Type</p></th>
<th class="tableblock halign-left valign-middle"><p class="tableblock">Default</p></th>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-infinispan-client_quarkus.infinispan-client.near-cache-max-entries"></a><code><a href="#quarkus-infinispan-client_quarkus.infinispan-client.near-cache-max-entries">quarkus.infinispan-client.near-cache-max-entries</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Sets the bounded entry count for near cache. If this value is 0 or less near cache is disabled.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">int</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>0</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-infinispan-client_quarkus.infinispan-client.server-list"></a><code><a href="#quarkus-infinispan-client_quarkus.infinispan-client.server-list">quarkus.infinispan-client.server-list</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Sets the host name/port to connect to. Each one is separated by a semicolon (eg. host1:11222;host2:11222).</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-infinispan-client_quarkus.infinispan-client.client-intelligence"></a><code><a href="#quarkus-infinispan-client_quarkus.infinispan-client.client-intelligence">quarkus.infinispan-client.client-intelligence</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Sets client intelligence used by authentication</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-infinispan-client_quarkus.infinispan-client.use-auth"></a><code><a href="#quarkus-infinispan-client_quarkus.infinispan-client.use-auth">quarkus.infinispan-client.use-auth</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Enables or disables authentication</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-infinispan-client_quarkus.infinispan-client.auth-username"></a><code><a href="#quarkus-infinispan-client_quarkus.infinispan-client.auth-username">quarkus.infinispan-client.auth-username</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Sets user name used by authentication</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-infinispan-client_quarkus.infinispan-client.auth-password"></a><code><a href="#quarkus-infinispan-client_quarkus.infinispan-client.auth-password">quarkus.infinispan-client.auth-password</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Sets password used by authentication</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-infinispan-client_quarkus.infinispan-client.auth-realm"></a><code><a href="#quarkus-infinispan-client_quarkus.infinispan-client.auth-realm">quarkus.infinispan-client.auth-realm</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Sets realm used by authentication</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-infinispan-client_quarkus.infinispan-client.auth-server-name"></a><code><a href="#quarkus-infinispan-client_quarkus.infinispan-client.auth-server-name">quarkus.infinispan-client.auth-server-name</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Sets server name used by authentication</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-infinispan-client_quarkus.infinispan-client.auth-client-subject"></a><code><a href="#quarkus-infinispan-client_quarkus.infinispan-client.auth-client-subject">quarkus.infinispan-client.auth-client-subject</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Sets client subject used by authentication</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-infinispan-client_quarkus.infinispan-client.auth-callback-handler"></a><code><a href="#quarkus-infinispan-client_quarkus.infinispan-client.auth-callback-handler">quarkus.infinispan-client.auth-callback-handler</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Sets callback handler used by authentication</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-infinispan-client_quarkus.infinispan-client.sasl-mechanism"></a><code><a href="#quarkus-infinispan-client_quarkus.infinispan-client.sasl-mechanism">quarkus.infinispan-client.sasl-mechanism</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Sets SASL mechanism used by authentication</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-infinispan-client_quarkus.infinispan-client.trust-store"></a><code><a href="#quarkus-infinispan-client_quarkus.infinispan-client.trust-store">quarkus.infinispan-client.trust-store</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Sets the trust store path</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-infinispan-client_quarkus.infinispan-client.trust-store-password"></a><code><a href="#quarkus-infinispan-client_quarkus.infinispan-client.trust-store-password">quarkus.infinispan-client.trust-store-password</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Sets the trust store password</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a id="quarkus-infinispan-client_quarkus.infinispan-client.trust-store-type"></a><code><a href="#quarkus-infinispan-client_quarkus.infinispan-client.trust-store-type">quarkus.infinispan-client.trust-store-type</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Sets the trust store type</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-middle"></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>It is also possible to configure a <code>hotrod-client.properties</code> as described in the Infinispan user guide. Note that
the <code>hotrod-client.properties</code> values overwrite any matching property from the other configuration values (eg. near cache).
This properties file is build time only and if it is changed, requires a full rebuild.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="serialization-key-value-types-support"><a class="anchor" href="#serialization-key-value-types-support"></a>Serialization (Key Value types support)</h2>
<div class="sectionbody">
<div class="paragraph">
<p>By default the client will support keys and values of the following types: byte[],
primitive wrappers (eg. Integer, Long, Double etc.), String, Date and Instant. User types require
some additional steps that are detailed here. Let&#8217;s say we have the following user classes:</p>
</div>
<div class="listingblock">
<div class="title">Author.java</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">public class Author {
   private final String name;
   private final String surname;

   public Author(String name, String surname) {
      this.name = Objects.requireNonNull(name);
      this.surname = Objects.requireNonNull(surname);
   }
   // Getter/Setter/equals/hashCode/toString omitted
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="title">Book.java</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">public class Book {
   private final String title;
   private final String description;
   private final int publicationYear;
   private final Set&lt;Author&gt; authors;

   public Book(String title, String description, int publicationYear, Set&lt;Author&gt; authors) {
      this.title = Objects.requireNonNull(title);
      this.description = Objects.requireNonNull(description);
      this.publicationYear = publicationYear;
      this.authors = Objects.requireNonNull(authors);
   }
   // Getter/Setter/equals/hashCode/toString omitted
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Serialization of user types uses a library based on protobuf, called Protostream.</p>
</div>
<div class="sect2">
<h3 id="annotation-based-serialization"><a class="anchor" href="#annotation-based-serialization"></a>Annotation based Serialization</h3>
<div class="paragraph">
<p>This can be done automatically by adding protostream annotations to your user classes.
In addition a single Initializer annotated interface is required which controls how
the supporting classes are generated.</p>
</div>
<div class="paragraph">
<p>Here is an example of how the preceding classes should be changed:</p>
</div>
<div class="listingblock">
<div class="title">Author.java</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">    @ProtoFactory
    public Author(String name, String surname) {
        this.name = Objects.requireNonNull(name);
        this.surname = Objects.requireNonNull(surname);
    }

    @ProtoField(number = 1)
    public String getName() {
        return name;
    }

    @ProtoField(number = 2)
    public String getSurname() {
        return surname;
    }</code></pre>
</div>
</div>
<div class="listingblock">
<div class="title">Book.java</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">    @ProtoFactory
    public Book(String title, String description, int publicationYear, Set&lt;Author&gt; authors) {
        this.title = Objects.requireNonNull(title);
        this.description = Objects.requireNonNull(description);
        this.publicationYear = publicationYear;
        this.authors = Objects.requireNonNull(authors);
    }

    @ProtoField(number = 1)
    public String getTitle() {
        return title;
    }

    @ProtoField(number = 2)
    public String getDescription() {
        return description;
    }

    @ProtoField(number = 3, defaultValue = "-1")
    public int getPublicationYear() {
        return publicationYear;
    }

    @ProtoField(number = 4)
    public Set&lt;Author&gt; getAuthors() {
        return authors;
    }</code></pre>
</div>
</div>
<div class="paragraph">
<p>If your classes have only mutable fields, then the <code>ProtoFactory</code> annotation
is not required, assuming your class has a no arg constructor.</p>
</div>
<div class="paragraph">
<p>Then all that is required is a very simple <code>SerializationContextInitializer</code> interface with an annotation
on it to specify configuration settings</p>
</div>
<div class="listingblock">
<div class="title">BookContextInitializer.java</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@AutoProtoSchemaBuilder(includeClasses = { Book.class, Author.class }, schemaPackageName = "book_sample")
interface BookContextInitializer extends SerializationContextInitializer {
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>So in this case we will automatically generate the marshaller and schemas for the included classes and
place them in the schema package automatically. The package does not have to be provided, but if you
utilize querying, you must know the generated package.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
In Quarkus the <code>schemaFileName</code> and <code>schemaFilePath</code> attributes should NOT be set on the <code>AutoProtoSchemaBuilder</code> annotation, setting either will cause native runtime to error.
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="user-written-serialization"><a class="anchor" href="#user-written-serialization"></a>User written serialization</h3>
<div class="paragraph">
<p>The previous method is suggested for any case when the user can annotate their classes.
Unfortunately the user may not be able to annotate all classes they will put in the
cache. In this case you must define your schema and create your own Marshaller(s)
yourself.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Protobuf schema</dt>
<dd>
<p>You can supply a protobuf schema through either one of two ways.</p>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Proto File
 <br>
  You can put the <code>.proto</code> file in the <code>META-INF</code> directory of the project. These files will
automatically be picked up at initialization time.</p>
<div class="listingblock">
<div class="title">library.proto</div>
<div class="content">
<pre>package book_sample;

message Book {
  required string title = 1;
  required string description = 2;
  required int32 publicationYear = 3; // no native Date type available in Protobuf

  repeated Author authors = 4;
}

message Author {
  required string name = 1;
  required string surname = 2;
}</pre>
</div>
</div>
</li>
<li>
<p>In Code
 <br>
  Or you can define the proto schema directly in user code by defining a produced bean of type
<code>org.infinispan.protostream.FileDescriptorSource</code>.</p>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">   @Produces
   FileDescriptorSource bookProtoDefinition() {
      return FileDescriptorSource.fromString("library.proto", "package book_sample;\n" +
            "\n" +
            "message Book {\n" +
            "  required string title = 1;\n" +
            "  required string description = 2;\n" +
            "  required int32 publicationYear = 3; // no native Date type available in Protobuf\n" +
            "\n" +
            "  repeated Author authors = 4;\n" +
            "}\n" +
            "\n" +
            "message Author {\n" +
            "  required string name = 1;\n" +
            "  required string surname = 2;\n" +
            "}");
   }</code></pre>
</div>
</div>
</li>
</ol>
</div>
</dd>
<dt class="hdlist1">User Marshaller</dt>
<dd>
<p>The last thing to do is to provide a <code>org.infinispan.protostream.MessageMarshaller</code> implementation
for each user class defined in the proto schema. This class is then provided via <code>@Produces</code> in a similar
fashion to the code based proto schema definition above.</p>
<div class="paragraph">
<p>Here is the Marshaller class for our Author &amp; Book classes.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The type name must match the <code>&lt;protobuf package&gt;.&lt;protobuf message&gt;</code> exactly!
</td>
</tr>
</table>
</div>
<div class="listingblock">
<div class="title">AuthorMarshaller.java</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">public class AuthorMarshaller implements MessageMarshaller&lt;Author&gt; {

   @Override
   public String getTypeName() {
      return "book_sample.Author";
   }

   @Override
   public Class&lt;? extends Author&gt; getJavaClass() {
      return Author.class;
   }

   @Override
   public void writeTo(ProtoStreamWriter writer, Author author) throws IOException {
      writer.writeString("name", author.getName());
      writer.writeString("surname", author.getSurname());
   }

   @Override
   public Author readFrom(ProtoStreamReader reader) throws IOException {
      String name = reader.readString("name");
      String surname = reader.readString("surname");
      return new Author(name, surname);
   }
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="title">BookMarshaller.java</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">public class BookMarshaller implements MessageMarshaller&lt;Book&gt; {

   @Override
   public String getTypeName() {
      return "book_sample.Book";
   }

   @Override
   public Class&lt;? extends Book&gt; getJavaClass() {
      return Book.class;
   }

   @Override
   public void writeTo(ProtoStreamWriter writer, Book book) throws IOException {
      writer.writeString("title", book.getTitle());
      writer.writeString("description", book.getDescription());
      writer.writeInt("publicationYear", book.getPublicationYear());
      writer.writeCollection("authors", book.getAuthors(), Author.class);
   }

   @Override
   public Book readFrom(ProtoStreamReader reader) throws IOException {
      String title = reader.readString("title");
      String description = reader.readString("description");
      int publicationYear = reader.readInt("publicationYear");
      Set&lt;Author&gt; authors = reader.readCollection("authors", new HashSet&lt;&gt;(), Author.class);
      return new Book(title, description, publicationYear, authors);
   }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>And you pass the marshaller by defining the following:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">   @Produces
   MessageMarshaller authorMarshaller() {
      return new AuthorMarshaller();
   }

   @Produces
   MessageMarshaller bookMarshaller() {
      return new BookMarshaller();
   }</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The above produced Marshaller method MUST return <code>MessageMarshaller</code> without types or else it will not be found.
</td>
</tr>
</table>
</div>
</dd>
</dl>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="dependency-injection"><a class="anchor" href="#dependency-injection"></a>Dependency Injection</h2>
<div class="sectionbody">
<div class="paragraph">
<p>As you saw above we support the user injecting Marshaller configuration. You can do the inverse with
the Infinispan client extension providing injection for <code>RemoteCacheManager</code> and <code>RemoteCache</code> objects.
There is one global <code>RemoteCacheManager</code> that takes all of the configuration
parameters setup in the above sections.</p>
</div>
<div class="paragraph">
<p>It is very simple to inject these components. All you need to do is to add the Inject annotation to
the field, constructor or method. In the below code we utilize field and constructor injection.</p>
</div>
<div class="listingblock">
<div class="title">SomeClass.java</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">    @Inject SomeClass(RemoteCacheManager remoteCacheManager) {
       this.remoteCacheManager = remoteCacheManager;
    }

    @Inject @Remote("myCache")
    RemoteCache&lt;String, Book&gt; cache;

    RemoteCacheManager remoteCacheManager;</code></pre>
</div>
</div>
<div class="paragraph">
<p>If you notice the <code>RemoteCache</code> declaration has an additional optional annotation named <code>Remote</code>.
This is a qualifier annotation allowing you to specify which named cache that will be injected. This
annotation is not required and if it is not supplied, the default cache will be injected.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Other types may be supported for injection, please see other sections for more information
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="querying"><a class="anchor" href="#querying"></a>Querying</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The Infinispan client supports both indexed and non indexed querying as long as the
<code>ProtoStreamMarshaller</code> is configured above. This allows the user to query based on the
properties of the proto schema.</p>
</div>
<div class="paragraph">
<p>Query builds upon the proto definitions you can configure when setting up the <code>ProtoStreamMarshaller</code>.
Either method of Serialization above will automatically register the schema with the server at
startup, meaning that you will automatically gain the ability to query objects stored in the
remote Infinispan Server.</p>
</div>
<div class="paragraph">
<p>You can read more about this at <a href="https://infinispan.org/docs/stable/titles/developing/developing.html#query_dsl" class="bare">https://infinispan.org/docs/stable/titles/developing/developing.html#query_dsl</a>.</p>
</div>
<div class="paragraph">
<p>You can use either the Query DSL or the Ickle Query language with the Quarkus Infinispan client
extension.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="counters"><a class="anchor" href="#counters"></a>Counters</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Infinispan also has a notion of counters and the Quarkus Infinispan client supports them out of
the box.</p>
</div>
<div class="paragraph">
<p>The Quarkus Infinispan client extension allows for Dependency Injection
of the <code>CounterManager</code> directly. All you need to do is annotate your field, constructor or method
and you get it with no fuss. You can then use counters as you would normally.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Inject
CounterManager counterManager;</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="near-caching"><a class="anchor" href="#near-caching"></a>Near Caching</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Near caching is disabled by default, but you can enable it by setting the profile config property
<code>quarkus.infinispan-client.near-cache-max-entries</code> to a value greater than 0. You can also configure
a regular expression so that only a subset of caches have near caching applied through the
<code>quarkus.infinispan-client.near-cache-name-pattern</code> attribute.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="encryption"><a class="anchor" href="#encryption"></a>Encryption</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Encryption at this point requires additional steps to get working.</p>
</div>
<div class="paragraph">
<p>The first step is to configure the <code>hotrod-client.properties</code> file to point to your truststore
and/or keystore. This is further detailed at
<a href="https://infinispan.org/docs/dev/user_guide/user_guide.html#hr_encryption" class="bare">https://infinispan.org/docs/dev/user_guide/user_guide.html#hr_encryption</a>.</p>
</div>
<div class="paragraph">
<p>The Infinispan Client extension enables SSL by default. You can read more about this
at <a href="native-and-ssl">Using SSL With Native Executables</a>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="authentication"><a class="anchor" href="#authentication"></a>Authentication</h2>
<div class="sectionbody">
<div class="paragraph">
<p>This chart illustrates what mechanisms have been verified to be working properly with
the Quarkus Infinispan Client extension.</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 1. Mechanisms</caption>
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Name</th>
<th class="tableblock halign-left valign-top">Verified</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">DIGEST-MD5</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong class="green">Y</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">PLAIN</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong class="green">Y</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">EXTERNAL</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong class="green">Y</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">GSSAPI</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong class="red">N</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Custom</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong class="red">N</strong></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>The guide for configuring these can be found at <a href="https://infinispan.org/docs/dev/user_guide/user_guide.html#authentication" class="bare">https://infinispan.org/docs/dev/user_guide/user_guide.html#authentication</a>.
However you need to configure these through the <code>hotrod-client.properties</code> file if using Dependency Injection.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="additional-features"><a class="anchor" href="#additional-features"></a>Additional Features</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The Infinispan Client has additional features that were not mentioned here. This means this
feature was not tested in a Quarkus environment and they may or may not work. Please let us
know if you need these added!</p>
</div>
</div>
</div>
    </div>
  </div>
</div>

  </div>

  <div class="content project-footer">
  <div class="footer-section">
    <div class="logo-wrapper">
      <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_reverse.svg" class="project-logo" title="Quarkus"></a>
    </div>
  </div>
  <div class="grid-wrapper">
    <p class="grid__item width-3-12">Quarkus is open. All dependencies of this project are available under the <a href='https://www.apache.org/licenses/LICENSE-2.0' target='_blank'>Apache Software License 2.0</a> or compatible license.<br /><br />This website was built with <a href='https://jekyllrb.com/' target='_blank'>Jekyll</a>, is hosted on <a href='https://pages.github.com/' target='_blank'>Github Pages</a> and is completely open source. If you want to make it better, <a href='https://github.com/quarkusio/quarkusio.github.io' target='_blank'>fork the website</a> and show us what you’ve got.</p>

    
      <div class="width-1-12 project-links">
        <span>Navigation</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="/">Home</a></li>
          
            <li><a href="/guides">Guides</a></li>
          
            <li><a href="/community/#contributing">Contribute</a></li>
          
            <li><a href="/faq">FAQ</a></li>
          
            <li><a href="/get-started">Get Started</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Contribute</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://twitter.com/quarkusio">Follow us</a></li>
          
            <li><a href="https://github.com/quarkusio">GitHub</a></li>
          
            <li><a href="/security">Security&nbsp;policy</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Get Help</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://groups.google.com/forum/#!forum/quarkus-dev">Forums</a></li>
          
            <li><a href="https://quarkusio.zulipchat.com">Chatroom</a></li>
          
        </ul>
      </div>
    

    
      <div class="width-3-12 more-links">
        <span>Quarkus is made of community projects</span>
        <ul class="footer-links">
          
            <li><a href="https://vertx.io/" target="_blank">Eclipse Vert.x</a></li>
          
            <li><a href="https://microprofile.io" target="_blank">Eclipse MicroProfile</a></li>
          
            <li><a href="https://hibernate.org" target="_blank">Hibernate</a></li>
          
            <li><a href="https://netty.io" target="_blank">Netty</a></li>
          
            <li><a href="https://resteasy.github.io" target="_blank">RESTEasy</a></li>
          
            <li><a href="https://camel.apache.org" target="_blank">Apache Camel</a></li>
          
            <li><a href="https://code.quarkus.io/" target="_blank">And many more...</a></li>
          
        </ul>
      </div>
    
  </div>
</div>
  <div class="content redhat-footer">
  <div class="grid-wrapper">
    <span class="licence">
      <i class="fab fa-creative-commons"></i><i class="fab fa-creative-commons-by"></i> <a href="https://creativecommons.org/licenses/by/3.0/" target="_blank">CC by 3.0</a> | <a href="https://www.redhat.com/en/about/privacy-policy">Privacy Policy</a>
    </span>
    <span class="redhat">
      Sponsored by
    </span>
    <span class="redhat-logo">
      <a href="https://www.redhat.com/" target="_blank"><img src="/assets/images/redhat_reversed.svg"></a>
    </span>
  </div>
</div>


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" integrity="sha384-8gBf6Y4YYq7Jx97PIqmTwLPin4hxIzQw5aDmUg/DDhul9fFpbbLcLh3nTIIDJKhx" crossorigin="anonymous"></script>
  <script type="text/javascript" src="/assets/javascript/mobile-nav.js"></script>
  <script type="text/javascript" src="/assets/javascript/scroll-down.js"></script>
  <script src="/assets/javascript/satellite.js" type="text/javascript"></script>
  <script src="https://quarkus.io/guides/javascript/config.js" type="text/javascript"></script>
  <script src="/assets/javascript/search-filter.js" type="text/javascript"></script>
  <script src="/assets/javascript/back-to-top.js" type="text/javascript"></script>
</body>

</html>
